<?php 
require('includes/class.main.php');
$manager = new MeetingManager();
include_once('./includes/class.search.php');
include_once('./includes/class.meeting.php');

include_once 'template/header.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
  
  <?php MeetingManager::echoMetaData(); ?>
  	
  <script type="text/javascript">
	
  	var locationAddresses = {
	<?php 

		$count = 0;
		$locations = MeetingSearch::getLocations();
		
		foreach ($locations as $location => $details) {
			echo "'$location' : { 'address' : '" . $details['address'] . 
				"', 'city' : '" . $details['city'] . "', 'zip' : '" .
				$details['zip'] . "'}";
			$count++;
			if ($count < count($locations)) { 
				echo ",\n";
			}
		}
		echo "\n";
	?>
  	};

  	function searchTypeChanged(value) {
		
		if (value == "exact") { 
			$("#radius").prop('disabled', true);
		} else { 
			$("#radius").prop('disabled', false);
		}
	}	
	
	function locationSelected(value) { 
		
		var readonly; 

		if (value == "") {
			readonly = false;
			$('#address').val("");
			$('#city').val("");
			$('#zip').val("");
		} else { 
			readonly = true;
		
			if (!locationAddresses[value]) {
				$('#address').val("");
				$('#city').val("");
				$('#zip').val("");
			} else {
				$('#address').val(locationAddresses[value].address);
				$('#city').val(locationAddresses[value].city);
				$('#zip').val(locationAddresses[value].zip);
			}
		}

		$("#address").prop('readonly', readonly); 
		$("#city").prop('readonly', readonly); 
		$("#zip").prop('readonly', readonly); 
		
	}
	
  	$(document).ready(function() {
  		$('input:radio[name=searchType]').on(navigator.userAgent.match(/msie/i) ? "propertychange" : "change", function(evt) {
  		    evt.preventDefault();
  		    searchTypeChanged(this.value);
  		    // Your code here
  		});
  		val = $('input[name=searchType]:checked', '#searchForm').val()
  		searchTypeChanged(val);
  		val = $('select[name=location]').val();
  		locationSelected(val);
  	});
  	  </script>
	
	</head>

  	<body>
  	<div class="content">
  	
  	<?php include_once 'template/menu.php'; ?>

  	<div class="center">
		<div class="searchForm">
			<!-- debugging 
			<form style="clear:both" id="searchForm" action="api/searchmeetings.php" method="get">
		 	-->
			<form style="clear:both" id="searchForm" action="results.php" method="get">
	 		
				<div class="column1">
					<b><span class="blue">Location Options</span></b>
					
					<br>
					<div style="width:20em;height:1em;clear:both;margin-top:1em;margin-bottom:1em;margin-left:auto;margin-right:auto;">
						<span  class="radioText">Search Nearby</span>
						<input id="nearbySearch"  type="radio" checked name="searchType" value="<?php echo SearchParams::NEARBY_SEARCH?>"  >
						<span class="radioText">Exact Match</span>
						<input id="exactSearch"  type="radio" name="searchType" value="<?php echo SearchParams::EXACT_SEARCH?>"  >
					</div>
					
					<span class="col1 label" >Location</span>
					<select id="location" name="location" onchange="locationSelected(this.value)">
						<option value=""></option>
						<?
						$locations = MeetingSearch::getLocations();
						
						foreach ($locations as $location => $details) {
						?>	
							<option value="<? echo $location; ?>"><? echo $details['displayName'];?></option>
						<? 
						}
						?>
					</select>
					<br>
					<span class="col1 label" >Address</span>
					<input id="address" style="width:19em" type="text" name="address"> 
					<br>
					<span class="col1 label">City</span>
					<input id="city" style="width:19em" type="text" name="city"> 
					<span class="col1 label">Zip</span>
					<input id="zip" style="width:5em" type="text" name="zip"> 
					<span class="label">Radius</span>
					<select id="radius" name="radius">
						<option value="5">5 Miles</option>
						<option value="10">10 Miles</option>
						<option value="20">20 Miles</option>
					</select>									
					<br>
					<br>
					<b><span class="blue">Day and Time Options</span></b>
					<br>
					<span class="label col1">Day</span>
					<select id="day" name="day">
						<option value=""></option>
				      	<option value="SUNDAY">Sunday</option>
				      	<option value="MONDAY">Monday</option>
				      	<option value="TUESDAY">Tuesday</option>
				      	<option value="WEDNESDAY">Wednesday</option>
				      	<option value="THURSDAY">Thursday</option>
				      	<option value="FRIDAY">Friday</option>
				      	<option value="SATURDAY">Saturday</option>
			      	</select>
			      	<br>
			      	<span class="col1 label">Between</span>
					<select id="startTime" name="startTime">
						<option value=""></option>
						<option value="1:00">1:00</option>
						<option value="2:00">2:00</option>
						<option value="3:00">3:00</option>
						<option value="4:00">4:00</option>
						<option value="5:00">5:00</option>
						<option value="6:00">6:00</option>
						<option value="7:00">7:00</option>
						<option value="8:00">8:00</option>
						<option value="9:00">9:00</option>
						<option value="10:00">10:00</option>
						<option value="11:00">11:00</option>
						<option value="12:00">12:00</option>
					</select>
					<select name="meridianStart">
						<option value="AM">AM</option>
						<option value="PM" selected>PM</option>
					</select>
			      	<span class="label" style="margin-left:.1em">And</span>
					<select id="endTime" name="endTime">
						<option value=""></option>
						<option value="1:00">1:00</option>
						<option value="2:00">2:00</option>
						<option value="3:00">3:00</option>
						<option value="4:00">4:00</option>
						<option value="5:00">5:00</option>
						<option value="6:00">6:00</option>
						<option value="7:00">7:00</option>
						<option value="8:00">8:00</option>
						<option value="9:00">9:00</option>
						<option value="10:00">10:00</option>
						<option value="11:00">11:00</option>
						<option value="12:00">12:00</option>
					</select>
			  		<select name="meridianEnd">
						<option value="AM">AM</option>
						<option value="PM" selected>PM</option>
					</select>
				</div>
				<div class="column2">
					<b><span class="blue">Meeting Info Options</span></b>
					<br>
								
					<span style="margin-top:1.2em" class="col1 label" >Group</span>
					<input id="group" style="width:15.5em;margin-top:.8em" type="text" name="group"> 
					<br>
	
					<span class="label col1">Codes</span>
			    	<select id="codes" name="codes[]" multiple size=12>
			    		<? 
			    		foreach (Meeting::getCodeDescs() as $code => $description) {
			  				if ($code == "%") {
			  			?>
			        		<option value="<? echo $code;?>"> <? echo "$description"; ?> </option>
			        	<? 
			  				} else {
			        	?>
			        		<option value="<? echo $code;?>"> <? echo "$description ($code)"; ?> </option>
			        	<? 
			  				}
			    		}
			    		?>
					</select>
					<span style="display:block;margin-top:.5em">(Hold CTRL key while clicking to add or remove codes)</span>
					<br>
				</div>
				<div style="width:5em;margin-top:5em;margin-right:auto;margin-left:auto">
					<input type="submit" style="height:2em;margin-right:auto;margin-left:auto;margin-top:1em" value="Search" name="submit">
				</div>
				
			</form>
		</div>
		<span style="font-style:italic; line-height:5em; float:right">Have a comment about our new Meetings Search? <a href="mailto:aaatlanta.org@gmail.com">Email us!</a></span>
	</div>	
	
	<? include('template/footer.php'); ?>
		
</div>


</body>
</html>

